<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

      <el-form-item label="宿舍栋号" prop="buildingNo">
        <el-select
          v-model="queryParams.buildingNo"
          placeholder="宿舍栋号"
          clearable
          size="small"
          style="width: 180px">
          <el-option
            v-for="dict in buildingNoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="楼层" prop="storey">
        <el-select
          v-model="queryParams.storey"
          placeholder="宿舍楼层"
          clearable
          size="small"
          style="width: 180px">
          <el-option
            v-for="dict in storeyOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

       <el-form-item label="宿舍号" prop="dormitoryNo">
         <el-input
           v-model="queryParams.dormitoryNo"
           placeholder="请输入宿舍号"
           clearable
           size="small"
           style="width: 180px"
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="dormitoryStaList" @selection-change="handleSelectionChange">
      <el-table-column label="宿舍栋号" align="center" prop="buildingNo" :show-overflow-tooltip="true" />
      <el-table-column label="楼层" align="center" prop="storey"  />
      <el-table-column label="宿舍号" align="center" prop="dormitoryNo" />
      <el-table-column label="准数人数" align="center" prop="stuCount" />
      <el-table-column label="已住人数" align="center" prop="stuCount1" />
      <el-table-column label="可住人数" align="center" prop="stuCount2" />

    </el-table>


   <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

   <!-- <bargraph :id="'bargraph'" :data="option2" style="height:350px;margin-top: 30px;"  ></bargraph> -->

  </div>
</template>

<script>
import { listDorStatistics} from "@/api/report/dormitorystatistics";

export default {
  name: "DormitorySta",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      dormitoryStaList: [],
      // 宿舍栋号
      buildingNoOptions: [],
      // 楼层
      storeyOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        buildingNo: undefined,
        storey: undefined,
        dormitoryNo: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
        }
      },
  components:{
     // bargraph
  },
  created() {
    this.getList();
    this.getDicts("sys_building").then(response => {
      this.buildingNoOptions = response.data;
    });
    this.getDicts("sys_storey").then(response => {
      this.storeyOptions = response.data;
    });
  },
  methods: {
    /** 查询宿舍人数列表 */
    getList() {
      this.loading = true;
      listDorStatistics(this.queryParams).then(response => {
          this.dormitoryStaList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    }

  }
};
</script>
